package com.ford.microservices.services.web;

import com.ford.microservices.common.AccountDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class CustomUserDetailsService implements UserDetailsService {
    @Autowired
    protected WebAccountsService accountsService;

    public CustomUserDetailsService(WebAccountsService accountsService) {
        this.accountsService = accountsService;
    }

    @Override
    public UserDetails loadUserByUsername(String cellPhone) throws UsernameNotFoundException {
        AccountDto user = accountsService.findByCellPhone(cellPhone);
        return new org.springframework.security.core.userdetails.User(user.getCellPhone(), user.getPassword(), new ArrayList<>());
    }
}
